<template>
  <el-container class="main_con">
    <div class="filter_con ds_block nopt">
      <div class="filter_area">
        <el-input
          size="medium"
          v-model="params.name"
          class="serach_input mr_15 mt_15"
          placeholder="用户名称"
        ></el-input>
        <el-input
          size="medium"
          v-model="params.mobile"
          class="serach_input mr_15 mt_15"
          placeholder="手机号码"
        ></el-input>
        <date-picker size="medium" @change="gettime" class="mr_15 mt_15"></date-picker>
        <el-button size="medium" @click="search">搜索</el-button>
      </div>
    </div>
    <div class="list_con">
      <el-table
        @selection-change="SelectHadnle"
        :data="list"
        element-loading-text
        fit
        highlight-current-row
      >
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column prop="name" label="用户名"></el-table-column>
        <el-table-column prop="p_name" label="关联上级用户"></el-table-column>
        <el-table-column prop="mobile" label="联系号码"></el-table-column>
        <el-table-column prop="status_text" label="状态"></el-table-column>
        <el-table-column prop="create_time" label="创建时间"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button v-has type="text" @click="EditapplyHandle(scope.row)">通过</el-button>
            <el-button v-has type="text" @click="refuseapply(scope.row)">拒绝</el-button>
            <!-- <el-button type="text" @click="handleClose(scope.row.id)">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <div class="table_footer">
        <!-- <el-button size="medium">批量删除
        </el-button>-->
        <el-pagination
          @current-change="ChangeCurrent"
          class="pages"
          background
          layout="prev, pager, next"
          :total="total"
          :page-count="page"
          :page-size="size"
          hide-on-single-page
        ></el-pagination>
      </div>
    </div>
    <el-dialog title="申请通过" :visible.sync="drawer" destroy-on-close width="500px">
      <editagent ref="editagent" @on-close="beClose" :id="id" :type="'apply'" :data="jsondata"></editagent>
    </el-dialog>
  </el-container>
</template>

<script>
import {
  agent_applylist,
  edit_agent_apply,
  del_agent_apply
} from "@/api/mall/agent";
import Editagent from "./components/Editagent";
import DatePicker from "@/components/DatePicker/index";
import { fitter_keyword } from "@/utils/index";
export default {
  data() {
    return {
      params: {
        name: "",
        mobile: "",
        status: ""
      },
      paramsdf: {},
      page: 1,
      size: 10,
      total: 0,
      listLoading: true,
      list: [],
      drawer: false,
      direction: "rtl",
      id: "",
      type: "apply",
      selectionData: [],
      jsondata: {},
      statuslist: [
        {
          value: 1,
          label: "启用"
        },
        {
          value: 0,
          label: "禁用"
        }
      ]
    };
  },
  components: {
    Editagent,
    DatePicker
  },
  mounted() {
    this.getlist();
  },

  methods: {
    search() {
      this.paramsdf = fitter_keyword(this.params);
      this.getlist();
    },
    refuseapply(data) {
      var data = {
        id: data.id,
        update_time: data.update_time,
        status: 2
      };
      var _this = this;
      this.$confirm("确认拒绝申请？")
        .then(_ => {
          edit_agent_apply(data).then(res => {
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    EditapplyHandle(data) {
      this.id = data.id;
      this.jsondata = data;
      this.type = "apply";
      this.drawer = true;
      this.$nextTick(()=>{
        this.$refs.editagent.getapply(data)
      })
    },
    //选择
    SelectHadnle(selection) {
      this.selectionData = selection;
    },
    //删除
    handleClose(id) {
      let _this = this;
      this.$confirm("确认删除？")
        .then(_ => {
          let data = {
            id: id
          };
          del_agent_apply(data).then(res => {
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    //编辑完成
    beClose() {
      (this.drawer = false), this.getlist();
    },
    //获取列表
    getlist() {
      this.listLoading = true;
      var data = this.paramsdf;
      agent_applylist(this.page, data).then(res => {
        var jsondata = res.msg;
        this.list = jsondata.data;
        this.total = jsondata.total;
        // this.list = response.data.items
        this.listLoading = false;
      });
    },
    //获取时间
    gettime(value) {
      this.params.begin_date = value[0];
      this.params.end_date = value[1];
    },
    //切换页码
    ChangeCurrent(page) {
      this.page = page;
      this.getlist();
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
